package com.zhuoshi.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhuoshi.bean.Wd_apartment_layoutModel;
import com.zhuoshi.bean.Wd_purposeModel;
import com.zhuoshi.service.Wd_apartment_layoutModelService;

@Controller
@RequestMapping("/layout")
public class Wd_apartment_layoutAction {
	@Autowired
	Wd_apartment_layoutModelService wd_apartment_layoutModelService ;
    
	@RequestMapping("/selectAll.do")
	public String selectAll(Wd_apartment_layoutModel record,Model model){
		List<Wd_apartment_layoutModel> list = wd_apartment_layoutModelService.selectAll(record);
		model.addAttribute("list", list);
		return "Wd_apartment_layout" ;
	}
	
	@RequestMapping("/Wd_apartment_layout_toAdd.do")
	public String wd_apartment_layout_toAdd(Model model){			
		return "Wd_apartment_layout_add" ;
	}
	
	@RequestMapping("/Wd_apartment_layout_add.do")
	public String wd_apartment_layout_add(Wd_apartment_layoutModel record,Model model){	
		wd_apartment_layoutModelService.insertSelective(record);
		return "redirect:/layout/selectAll.do" ;
	}
	
	@RequestMapping("/Wd_apartment_layout_toUpdate.do")
	public String wd_apartment_layout_toUpdate(Wd_apartment_layoutModel record,Model model){	
		Wd_apartment_layoutModel bean = wd_apartment_layoutModelService.selectByPrimaryKey(record.getApartmentLayoutId());
		model.addAttribute("bean", bean);
		return "Wd_apartment_layout_update" ;
	}
	
	@RequestMapping("/Wd_apartment_layout_update.do")
	public String wd_apartment_layout_update(Wd_apartment_layoutModel record,Model model){	
		wd_apartment_layoutModelService.updateByPrimaryKeySelective(record);
		return "redirect:/layout/selectAll.do" ;
	}
	
	@RequestMapping("/Wd_apartment_layout_delete.do")
	public String Wd_apartment_layout_delete(String apartmentLayoutId){	
		wd_apartment_layoutModelService.deleteByPrimaryKey(apartmentLayoutId);
		return "redirect:/layout/selectAll.do" ;
	}
	
	@InitBinder
	public void InitBinder(ServletRequestDataBinder binder){
		binder.registerCustomEditor(Date.class, 
				new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
		
	}
}
